<template>
	<div class="tpl29-header"   
   :style="tplItemData.modulePadding || tplItemData.modulePadding ==0?'padding-top:'+tplItemData.modulePadding+'px;padding-bottom:'+tplItemData.modulePadding+'px;':'padding-top:5px;padding-bottom:5px;'">
    <!-- 折叠轮播 -->
    <div ref="getHeight"  class="imgAdv-box">

      <!-- 小程序端用swiper -->
      <wx-swiper class="my-swipe" :style="`height: ${imgadvWxH}`" indicator-color="#ebedf0" :circular="true" indicator-active-color="#FE5000" :autoplay="autoplay" :indicator-dots="showIndicators">
        <wx-swiper-item v-for="(item,index) in tplItemData.dataset" :key="index">
          <a @click="openLink(item.link)">
            <img :src="item.pic" alt="" @load="onImageLoad($event)"/>
          </a>
        </wx-swiper-item>
      </wx-swiper>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { openPage } from '@/utils/utils'
import { Swipe, SwipeItem } from 'vant'

Vue.use(Swipe)
Vue.use(SwipeItem)
export default Vue.extend({
  name: 'index',
  data() {
    return {
      imgadvWxH: '0',
      canScrollX: true,
      showIndicators: true,
      autoplay: true,
      keyword: ''
    }
  },
  props: {
    tplItemData: {
      type: Object // 传入参数的类型
    }
  },
  methods: {
    // TODO 小程序跳转
    openLink(link) {
        openPage(link)
    },
    // TODO 小程序swiper获取图片高度
    onImageLoad(event) {
      const imgHeight = event.detail.height
      if (imgHeight > parseFloat(this.imgadvWxH)) {
        this.imgadvWxH = `${imgHeight}px`
      }
    }
  },

  created() {

  }
})
</script>

<style lang='scss'>
 @import "src/styles/mixin";
.tpl29-header{
  position: relative;
  .imgAdv-box{
    // padding-top: 160px;
    img{
      display:block;
      width: 100%;
      padding-top: 15px;
    }
  }
}

</style>
